package com.fxnotes.common.ui;

import java.util.ArrayList;
import java.util.List;

public class NavigationPath {

    private final List<String> elements = new ArrayList<>();

    protected NavigationPath() {
    }

    protected NavigationPath(List<String> elements) {
        this.elements.addAll(elements);
    }

    public boolean match(String name) {
        if (elements.isEmpty()) {
            return false;
        }

        return elements.get(0).equals(name);
    }

    public String head() {
        if (elements.isEmpty()) {
            return "";
        }

        return elements.get(0);
    }

    public NavigationPath tail() {
        if (elements.isEmpty()) {
            return new NavigationPath();
        }

        List<String> tailElements = elements.subList(1, elements.size());
        return new NavigationPath(tailElements);
    }
    
    public boolean isLeaf() {
        return elements.size() == 1;
    }    

    @Override
    public String toString() {
        return "NavigationPath{" + "elements=" + elements + '}';
    }
}
